home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / LSEARCH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  739 b   |  24 lines

  1. /*  lsearch.c - search an ordered array of integers for a value */
  2. /*  from the BTREE collection */
  3. #include   "stdio.h"
  4.  
  5. int  lsearch(target,a,na,pwhere)    /* search an array for a value */
  6.   int    target     ;            /* look for this value */
  7.   int    a[]   ;             /* the array to search */
  8.   int    na    ;             /* size of the array */
  9.   int    *pwhere ;            /* store ending subscript here */
  10.   {
  11.      int   i , ret ;
  12.  
  13.      for(i=1 ; i<na ; i=i+1 )        /* scan each element in array */
  14.     {  ret = a[i] - target ;    /* compare target to array element */
  15.        if( ret == 0 )        /* we're thru if it maches */
  16.           break  ;
  17.     }
  18.      *pwhere = i ;            /* record where the search ended */
  19.      return( ret ) ;            /* return result of last compare */
  20.   }
  21.  
  22.  
  23.  
  24.